package com.hwadee.hello.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {
	@Pointcut("execution(* com.hwadee.hello.service.StudentService.add(..))")
	public void log() {}

	@Before("log()")
	public void logBefore(JoinPoint joinpoint) {

		System.out.println("logBefore() is running!");
		System.out.println("hijacked : " + joinpoint.getSignature().getName());
		System.out.println("******");
	}
	
	@Around("log()")
	public Object logAround(ProceedingJoinPoint joinpoint) throws Throwable {
		Object obj = null;
		try {
			System.out.println("之前");
			obj = joinpoint.proceed();
			System.out.println("之后");
		} catch (Exception e) {
			System.out.println("抛出");
		} 
		return obj;
	}

}
